package com.yss.reportworld.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yss.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yss.reportworld.service.IDataModularService;
import com.yss.reportworld.mapper.DataModularMapper;
import com.yss.reportworld.domain.DataModular;

/**
 * 基础数据对应模块信息Service业务层处理
 *
 * @author yss
 * @date 2023-03-24
 */
@Slf4j
@Service
public class DataModularServiceImpl extends ServiceImpl<DataModularMapper, DataModular> implements IDataModularService {

    /**
     * 查询对应数据和模块对应关系
     *
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, List<String>> getDataModularMap() {
        // 所属模块 code和数据，对应一个list
        QueryWrapper<DataModular> wrapper = new QueryWrapper<>();
        List<DataModular> modularList = this.list(wrapper);
        if (StringUtils.isEmpty(modularList)) {
            return null;
        }
        Map<String, List<String>> mapDataModular = new HashMap<>();
        for (DataModular modular : modularList) {
            if (null == modular || StringUtils.isEmpty(modular.getDataId()) || StringUtils.isEmpty(modular.getDataCode())) {
                continue;
            }
            String key = modular.getDataCode() + "\t" + modular.getDataId();
            if (mapDataModular.containsKey(key)) {
                List<String> list = mapDataModular.get(key);
                list.add(modular.getModularId());
                mapDataModular.put(key, list);
            } else {
                List<String> list = new ArrayList<>();
                list.add(modular.getModularId());
                mapDataModular.put(key, list);
            }
        }
        return mapDataModular;
    }

}
